package com.example.demo.util;


import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;

/**
 * @Author: huanggaotao
 * @Description:
 * @Date: Created in 16:01 2021/4/16
 * @Modified By:
 */
public class JwtTest {

        private static String SING_KEY = "hgtSignKey";


    public static void main(String[] args) {

        JwtBuilder hunggaotao = Jwts.builder().setId("1").setSubject("hunggaotao")
                .setIssuedAt(new Date())
                //设置签名值
                .signWith(SignatureAlgorithm.HS256, SING_KEY);

        //eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIxIiwic3ViIjoiaHVuZ2dhb3RhbyIsImlhdCI6MTYxODk4NjMwNn0.vZAYmxleOMhfhpgbY3pN_ChFQxj2CNnL5PMm0xaIjSU
        System.out.println(hunggaotao.compact());


        JwtBuilder userId = Jwts.builder()
                .setIssuedAt(new Date())
                .claim("userId", "644064")
                //设置签名值
                .signWith(SignatureAlgorithm.HS256, SING_KEY);

        System.out.println(userId.compact());


    }
}
